home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / rtx / update0.dif < prev   
Text File  |  1994-08-27  |  5KB  |  161 lines

  1. *** /tmp/,RCSt1a00896    Wed Nov 28 09:31:16 1990
  2. --- PatchLevel.h    Wed Nov 28 09:30:44 1990
  3. ***************
  4. *** 1,5 ****
  5.   /*
  6. !  *    PathLevel: 1
  7.    *
  8.    *    the Patch Level above is to identify the version
  9.    *    of the all the files in this directory. given the above
  10. --- 1,5 ----
  11.   /*
  12. !  *    PathLevel: 2
  13.    *
  14.    *    the Patch Level above is to identify the version
  15.    *    of the all the files in this directory. given the above
  16. *** /tmp/,RCSt1a00896    Wed Nov 28 09:31:18 1990
  17. --- phil.c    Wed Nov 28 09:30:45 1990
  18. ***************
  19. *** 44,66 ****
  20.        {"phil-4", (char *)NULL, 0x010, 4, 3, 0, 64, 0L, 0L, 0L, 0L, 0 }
  21.   };
  22.   
  23. ! /* forks: number of forks available to philosopher i
  24.    * note: mutex access at all times (ie only one process may read/write
  25. !  * any element of forks at one time, implemented via semaphore).
  26.    * usage:
  27. !  * at any time forks[i] can only be 0, 1, or 2
  28. !  * when a philosopher [i] wants to eat, forks[i] must be 2,
  29.    * if it is
  30. !  *    decrement forks to the right and left by one and start eating
  31.    * otherwise
  32. !  *    wait for event phil[i].event (ready condition for phil i) to occur.
  33.    *
  34. !  * when a philosopher is done eating,
  35. !  *    increments forks to left and right
  36. !  *    if forks[left] == 2    cause event phil[left].event
  37. !  *    if forks[right] == 2    cause event phil[right].event
  38.    */
  39. ! int forks [] = { 2, 2, 2, 2, 2 };
  40.   
  41.   /* fork semaphore (queue) */
  42.   char *forkSemaphore;
  43. --- 44,65 ----
  44.        {"phil-4", (char *)NULL, 0x010, 4, 3, 0, 64, 0L, 0L, 0L, 0L, 0 }
  45.   };
  46.   
  47. ! /* forks: number of forks (according to the number of philosophers
  48.    * note: mutex access at all times (ie only one process may read/write
  49. !  * one fork at one time, implemented via semaphore).
  50.    * usage:
  51. !  * at any time forks[i] can only be 0 or 1
  52. !  * when a philosopher [i] wants to eat, forks[i] and forks[(i+1)%5]
  53. !  * must be 1
  54.    * if it is
  55. !  *    decrement this two forks by one and start eating
  56.    * otherwise
  57. !  *    wait for event phil[i].event (ready condition for phil i) to occur
  58. !  *      and check again
  59.    *
  60. !  * when a philosopher has done eating he puts back his two forks
  61.    */
  62. ! int forks [] = { 1, 1, 1, 1, 1 };
  63.   
  64.   /* fork semaphore (queue) */
  65.   char *forkSemaphore;
  66. ***************
  67. *** 87,102 ****
  68.   PHIL *phil;    /* philosopher requesting forks */
  69.   {
  70.       Pfork(phil->message);    /* mutually exclusive access to forks */
  71. !     if(forks[phil->me] != 2)
  72. !     {
  73.       Vfork(phil->message);    /* release */
  74.       phil->eventbuf = phil->event;
  75.       e_wait(&phil->eventbuf, 0, 0L); /* wait for ready condition */
  76.       Pfork(phil->message);
  77. !     }
  78.       /* get the two forks */
  79. !     forks[phil->left]--;    
  80. !     forks[phil->right]--;
  81.       Vfork(phil->message);
  82.   }
  83.   
  84. --- 86,108 ----
  85.   PHIL *phil;    /* philosopher requesting forks */
  86.   {
  87.       Pfork(phil->message);    /* mutually exclusive access to forks */
  88. !     while (1)
  89. !      {
  90. !       if(forks[phil->me] == 0 || forks[phil->right] == 0)
  91. !        {
  92.       Vfork(phil->message);    /* release */
  93.       phil->eventbuf = phil->event;
  94.       e_wait(&phil->eventbuf, 0, 0L); /* wait for ready condition */
  95.       Pfork(phil->message);
  96. !        }
  97. !       else
  98. !        {
  99. !            break;
  100. !        }
  101. !      }
  102.       /* get the two forks */
  103. !     forks[phil->me]=0;    
  104. !     forks[phil->right]=0;
  105.       Vfork(phil->message);
  106.   }
  107.   
  108. ***************
  109. *** 111,121 ****
  110.       Pfork(phil->message);
  111.   
  112.       /* drop forks and signal any events */
  113.       if(++forks[phil->left] == 2)
  114.       e_signal(phils[phil->left].pid, phils[phil->left].event);
  115.       if(++forks[phil->right] == 2)
  116.       e_signal(phils[phil->right].pid, phils[phil->right].event);
  117.       Vfork(phil->message);
  118.   }
  119.   
  120. --- 117,132 ----
  121.       Pfork(phil->message);
  122.   
  123.       /* drop forks and signal any events */
  124. +     forks[phil->me] = 1;
  125. +     forks[phil->right] = 1;
  126. +     e_signal(phils[phil->left].pid, phils[phil->left].event);
  127. +     e_signal(phils[phil->right].pid, phils[phil->right].event);
  128. + /* 
  129.       if(++forks[phil->left] == 2)
  130.       e_signal(phils[phil->left].pid, phils[phil->left].event);
  131.       if(++forks[phil->right] == 2)
  132.       e_signal(phils[phil->right].pid, phils[phil->right].event);
  133. ! */
  134.       Vfork(phil->message);
  135.   }
  136.   
  137. ***************
  138. *** 142,151 ****
  139.       moveto(4, phil->col); printf("  Eating    "); fflush(stdout);
  140.       Vscreen(phil->message);
  141.       p_pause( (long)(((Rand() & 15) + 1) * 1000L) );
  142. -     putdown(phil);
  143.       Pscreen(phil->message);
  144.       moveto(4, phil->col); printf("  Thinking  "); fflush(stdout);
  145.       Vscreen(phil->message);
  146.       p_pause( (long)(((Rand() & 15) + 1) * 1000L) );
  147.       }
  148.       /*NOTREACHED*/
  149. --- 153,162 ----
  150.       moveto(4, phil->col); printf("  Eating    "); fflush(stdout);
  151.       Vscreen(phil->message);
  152.       p_pause( (long)(((Rand() & 15) + 1) * 1000L) );
  153.       Pscreen(phil->message);
  154.       moveto(4, phil->col); printf("  Thinking  "); fflush(stdout);
  155.       Vscreen(phil->message);
  156. +     putdown(phil);
  157.       p_pause( (long)(((Rand() & 15) + 1) * 1000L) );
  158.       }
  159.       /*NOTREACHED*/
  160.